package queue;

/**
 * 用队列实现栈 -225
 *
 * @author yyz
 * @create 2024-01-08 12:35
 */
public class 用队列实现栈 {
    private final ArrayQueue2<Integer> q = new ArrayQueue2<>(100);
    private int size = 0;

    public void push(int x) {
        q.offer(x);
        for (int i = 0; i < size; i++) {
            q.offer(q.poll());
        }
        size++;
    }

    public int pop() {
        size--;
        return q.poll();
    }

    public int top() {
        return q.peek();
    }

    public boolean empty() {
        return size == 0;
    }
}
